cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(AxonLogger VERSION 1.0.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17) # 使用C++17标准
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON) # 建议开启，便于生成共享库
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # 生成compile_commands.json

# 将编译输出目录设置到 build/bin
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)    

if(NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose build type: Debug Release RelWithDebInfo MinSizeRel")
endif()

# --- 将 moodycamel::ConcurrentQueue 添加为子项目 ---
add_subdirectory(external/moodycamel_queue) 

add_subdirectory(external/nlohmann_json) # 这会执行 nlohmann_json/CMakeLists.txt

add_subdirectory(external/fmt)

# 定义日志库的头文件目录
include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}/include
)

# 查找libcurl库
find_package(CURL REQUIRED)  # REQUIRED 表示如果找不到就报错

# 启用测试
enable_testing()

# 查找GTest
find_package(GTest REQUIRED)

# 定义MyLogger库
# 这是一个静态库，应用程序将链接到它
add_library(AxonLogger STATIC
    src/logger_factory.cpp
    src/logger_builder.cpp
    src/core/logger.cpp
    src/core/async_worker.cpp
    src/core/log_context.cpp
    src/core/logger_config.cpp
    src/core/log_entry.cpp
    src/sinks/console_color_sink.cpp
    src/sinks/rotating_file_sink.cpp
    src/sinks/filtering_sink.cpp
    src/sinks/network_sink.cpp
    src/formatters/basic_formatter.cpp
    src/formatters/json_formatter.cpp
    src/metrics/metrics_collector.cpp
    src/io/console_writer.cpp
    src/io/rotating_file_writer.cpp
)

# 链接到子项目spdlog 和 concurrentQueue 到 MyLogger 库
target_link_libraries(AxonLogger PUBLIC 
    concurrentqueue 
    nlohmann_json::nlohmann_json 
    CURL::libcurl
    fmt::fmt
)

# --- 安装规则 ---
include(GNUInstallDirs)

# 安装目标（库文件）
install(TARGETS AxonLogger
    EXPORT AxonLoggerTargets
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

# 安装头文件
install(DIRECTORY include/
    DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)


# --- 示例和测试的配置 ---

# 添加一个示例可执行文件
add_executable(basic_usage examples/basic_usage.cpp)
target_link_libraries(basic_usage PRIVATE AxonLogger)

# 添加一个测试可执行文件 （多种混合测试）
add_executable(test_perf tests/test_pref.cpp)
target_link_libraries(test_perf PRIVATE AxonLogger)




